<?php
/**
 * 货品列表模型
 * @author e5
 *
 */
class GoodsListModel extends Model{
	public $table = "goodslist";
	public $validate = array(
			array("combine","nonull","请选择规格",2,3),
			array("glnumber","maxlen:30","货号最大为30位",2,3),
			array("glinventory","num:0,65534","库存范围为0-65534")
	);
	public $auto = array(
			array("gid","intval","function",2,1)
	);
	public $map = array(
			"gid"=>"vshop_goods_gid"
	);
	/**
	 * 添加货品
	 */
	public function addGoodsList(){
		if (!$this->create()) return false;
		foreach (Q("post.combine",array()) as $v){
			if ($v == ""){
				$this->error = "请将规格选择全";
				return false;
			}
		}
		$this->data['combine'] = implode(",", Q("post.combine",array()));
		$combine = $this->data['combine'];
		if ($this->where("combine='{$combine}'")->count() > 0){
			$this->error = "货品已存在";
			return false;
		}
		return $this->add();
	}
	/**
	 * 编辑货品
	 * @return boolean
	 */
	public function editGoodsList() {
		if (!$this->create()) return false;
		foreach (Q("post.combine",array()) as $v){
			if ($v == ""){
				$this->error = "请将规格选择全";
				return false;
			}
		}
		$this->data['combine'] = implode(",", Q("post.combine",array()));
		$this->update();
		return true;
	}
}